/**
 * Copyright (c) 1987-2010 Fujian Fujitsu Communication Software Co., Ltd. All
 * Rights Reserved. This software is the confidential and proprietary
 * information of Fujian Fujitsu Communication Software Co., Ltd.
 * ("Confidential Information"). You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with FFCS. FFCS MAKES NO REPRESENTATIONS OR
 * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. FFCS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */
package com.xhui.vimarket.zkplus.zul.attr.mod.impl;t java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.directwebremoting.util.Logger;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Tabpanel;

import com.xhui.crm.common.vo.RetVO;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attrcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zul.attr.adacom.xhui.vimarket.zkpluser;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.AttrInst;
import com.xhui.vimcom.xhui.vimarket.zkplusl.attr.bean.AttrTmpl;
import com.xhui.vimarket.zkplus.zul.attr.mod.AttrCcom.xhui.vimarket.zkplus/**
 * @版权：福富软件 版权所有 (c) 2010
 * @文件：com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrWarperComp.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：属性控件接口，外层控件，不实例化不生成界面
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
public final class AttrTabboxContentComp extends AttrBaseComp {
    
    /**
     * 实例.
     */
    private static AttrTabboxContentComp inst   = new AttrTabboxContentComp();
    
    /**
     * 日志.
     */
    private static Logger                logger = Logger.getLogger(AttrTabboxContentComp.class);
    
    /**
     * 构造函数. 
     */
    private AttrTabboxContentComp() {
    }
    
    /**
     * 获取实例.
     * 
     * @return AttrBaseComp
     */
    public static AttrTabboxContentComp instance() {
        return AttrTabboxContentComp.inst;
    }
    
    /**
     * 生成组件.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 组件模板
     * @param comp 显示容器组件
     */
    @Override
    public void create(final AttrExt attrExt, final AttrTmpl attrTmpl, final Component comp) {
        super.create(attrExt, attrTmpl, comp);
        // create warper
        Tabpanel tabpanel = new Tabpanel();
        tabpanel.setParent(comp);
        tabpanel.setAttribute(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
        // create sub
        final int sum = attrTmpl.getAttrTmplListCount();
        for (int i = 0; i < sum; i++) {
            final AttrTmpl subAttrTmpl = attrTmpl.getAttrTmplList(i);
            AttrCompFactory.getInst(subAttrTmpl.getDisplayMode()).create(attrExt, subAttrTmpl,
                tabpanel);
        }
        
        super.afterCreate(attrExt, attrTmpl, comp);
    }
    
    /**
     * 设置值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param attrInstList 属性实例
     */
    @Override
    public void setValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList, final Map<String, Integer> attrViewMap) {
        super.setValue(attrExt, comp, attrInstList, attrViewMap);
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            AttrCompFactory.getInstByComponent(subCompRootBox).setValue(attrExt, subCompRootBox,
                attrInstList, attrViewMap);
    com.xhui.vimarket.zkplus   
    /**
     * {@inheritDoc}
     * @see com.xhui.com.xhui.vimarket.d.AttrComp
     * #setRemovedValue(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component, java.util.List)
     * @author wuyx
     * 2011-4-8 wuyx
     */
    public void setRemovedValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList) {
        super.setRemovedValue(attrExt, comp, attrInstList);
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            AttrCompFactory.getInstByComponent(subCompRootBox).setRemovedValue(attrExt,
                subCompRootBox, attrInstList);
        }
    }
    
    /**
     * 获取值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getValue(final AttrExt attrExt, final Component comp) {
        super.getValue(attrExt, comp);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            if (subCompRootBox != null) {
                final ArrayList<AttrInst> subRetList = AttrCompFactory.getInstByComponent(
                    subCompRootBox).getValue(attrExt, subCompRootBox);
                if (subRetList != null) {
                    retList.addAll(subRetList);
                }
            }
        }
        return retList;
    }
    
    /**
     * 取空值属性实例.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 模板
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getNullValue(final AttrExt attrExt, final AttrTmpl attrTmpl) {
        super.getNullValue(attrExt, attrTmpl);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        for (final AttrTmpl subAttrTmpl : attrTmpl.getAttrTmplList()) {
            final ArrayList<AttrInst> subRetList = AttrCompFactory.getInst(
                subAttrTmpl.getDisplayMode()).getNullValue(attrExt, subAttrTmpl);
            if (subRetList != null) {
                retList.addAll(subRetList);
            }
        }
        return retList;
    }
    
    /**
     * 清空值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     */
    @Override
    public void clean(final AttrExt attrExt, final Component comp) {
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            AttrCompFactory.getInstByComponent(subCompRootBox).clean(attrExt, subCompRootBox);
        }
    }
    
    /**
     * 设置为不允许修改.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param tflag 设置值，true/false
     */
    @Override
    public void setDisabled(AttrExt attrExt, Component comp, boolean tflag) {
        super.setDisabled(attrExt, comp, tflag);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            if (subCompRootBox != null) {
                AttrCompFactory.getInstByComponent(subCompRootBox).setDisabled(attrExt,
                    subCompRootBox, tflag);
 com.xhui.vimarket.zkplus       }
    }
    
    /**
     com.xhui.vimarket.zkplus
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.AttrComp#
     * exec(com.xhui.vimarket.zkplus.zul.attr.ada.AttrExecListener)
     * @author wuyx
     * 2011-3-16 wuyx
     */
    @SuppressWarnings("unchecked")
    @Override
    public void exec(final AttrExt attrExt, final Component comp, AttrExecListener attrExecListener) {
        super.exec(attrExt, comp, attrExecListener);
        if (attrExecListener == null) {
            return;
        }
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            if (subCompRootBox != null) {
                // 下级
                AttrCompFactory.getInstByComponent(subCompRootBox).exec(attrExt, subCompRootBox,
                    attrExecListener);
                // 自身
                attrExecListener.onEvent(subCompRoocom.xhui.vimarket.zkplus
            }
        }
    }
    
    /**
com.xhui.vimarket.zkplustDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp
     * #validate(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2011-3-22 wuyx
     */
    @Override
    public List<RetVO> validate(AttrExt attrExt, Component comp) {
        final List<RetVO> retList = new ArrayList<RetVO>();
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            if (subCompRootBox != null) {
                final List<RetVO> subRetList = AttrCompFactory.getInstByComponent(subCompRootBox)
                    .validate(attrExt, subCompRootBox);
                if (subRetList != null) {
                    retList.addAll(subRetList);
         com.xhui.vimarket.zkplus       }
        }
        return retList;
    }
    
com.xhui.vimarket.zkplus {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp
     * #refreshButtonText(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2011-3-24 wuyx
     */
    @Override
    public void refreshButtonText(AttrExt attrExt, Component comp, final List<AttrInst> attrInstList) {
        final List<RetVO> retList = new ArrayList<RetVO>();
        // 自身不实例化，取下级数据
        // sub component
        final List<Component> subCompList = comp.getChildren();
        for (final Component subCompRootBox : subCompList) {
            if (subCompRootBox != null) {
                AttrCompFactory.getInstByComponent(subCompRootBox).refreshButtonText(attrExt,
                    subCompRootBox, attrInstList);
            }
        }
    }
    
}
